﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Critterz
{
    public abstract class Organism
    {
        // How should the Map be assigned?  Each organism needs a "Map" to live on.
        public MapLocation location { get; set; }
        
        public int weight { get; private set; }
        public int energyYield { get; private set; }
        public bool alive { get; private set; }
        public System.Guid identification;

        private Map world;
        private int energyStore;

        public Organism(MapLocation mapLoc)
        {
            this.world = Map.getInstance(); // Map needs to be made into a singleton
            if (world.addOrganism(mapLoc, this))
            {
                this.alive = true;
            }
            else
            {
                // trash this object
            }
            
            this.identification = System.Guid.NewGuid();
        }

        private bool die()
        {
             this.alive = false;
             // Perhaps change into another organism subclass, "corpse"
             return true;
        }

        private void consume(Organism organism)
        {
            // todo
            if (!organism.alive && useEnergy(123456789))
            {
                 //destroy(organism);
            }
        }

        private void metabolize(int energyYield)
        {
            // Ideally this should take place over several turns, not just one.
            // This should also be generalized (or made abstract) to apply to plants that consume sunlight..
            // So plants need a new class to treat as food.
            this.energyStore += energyYield;
        }

        private bool useEnergy(int effortMultiplier)
        {
            int energyCost = effortMultiplier * this.weight;
            if (this.energyStore - energyCost > 0)
            {
                this.energyStore -= energyCost;
                return true;
            }
            else
            {
                return false;
            }
        }

        private bool mate()
        {
            // todo
            return false;
        }

    }
}
